package com.example.rabbitmq_study.workqueue;

import com.example.rabbitmq_study.util.RabbitmqUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author Huangyt
 * @version 1.0
 * @date 2020/7/28 21:51
 */
public class Provider {
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = RabbitmqUtil.getConnection();
        //创建通道
        Channel channel = connection.createChannel();
        //队列声明
        channel.queueDeclare("work", true, false, false, null);
        //发布10次消息
        for (int i = 1; i < 20; i++) {
            channel.basicPublish("", "work", MessageProperties.PERSISTENT_BASIC, ("hello work queue" + i).getBytes());
        }

        //关闭通道、连接
        RabbitmqUtil.close(channel, connection);
    }
}
